﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MVCMamage.DAL;
using MVCManage.Model;
using MVCManage.Model.Base;
namespace MVCManage.BLL
{
    public class RoleBLL:BaseBLL<Roles>
    {
        RoleDAL role = new RoleDAL();
        public List<Roles> RoleList() {
            return role.SelectRole().ToList();
        }

        public override void SetDal()
        {
            Dal = new RoleDAL();
        }
        public List<Roles> GetRolesPagelist(string name,int page,int size,out int count) {
            var list = Dal.Query();
            if (!string.IsNullOrWhiteSpace(name)) {
                list = list.Where(n => n.roleName.Contains(name));
            }
            count = list.Count();
            var pagelist = list.OrderBy(n => n.roleID).Skip((page - 1) * size).Take(size);
            return pagelist.ToList();
        
        }
        public bool Delete(int id) {
            var zhi = Dal.Query().Where(n => n.roleID == id).FirstOrDefault();
            Dal.Delete(zhi);
            return Dal.SaveChanges();
        }
        public bool Deletes(int[] ids) {
            var zhi = Dal.Query().Where(n => ids.Contains(n.roleID)).ToList();
            Dal.Deletes(zhi);
            return Dal.SaveChanges();
        }
    }
}
